import { defineStore } from 'pinia'
import { toRaw } from 'vue'

export const useUsersStore = defineStore('user', {
  state: () => ({ userList: [] }),
  getters: {},
  actions: {
    setUserList(payload) {
      this.userList = payload
    },
    updateUserInfo({ id, data }) {
      const target = this.userList.find((item) => item.id === id)
      for (const key in data) {
        target[key] = data[key]
      }
      window.nodeApi?.saveUserList(toRaw(this.userList))
    }
  }
})
